package model;

import java.util.ArrayList;
import java.util.Collection;

public class Cell {

	private int x;
	private int y;
	private State currentState;
	private State nextState;
	private Collection<Cell> neighbours;

	public Cell(int x, int y, State state) {
		this.x = x;
		this.y= y;
		currentState = state;
		nextState = null;
		neighbours = new ArrayList<Cell>();
	}
	
	public void update(){
		currentState = nextState;
		nextState = null;
	}

	public int getY() {
		return y;
	}

	public int getX() {
		return x;
	}

	public boolean isAlive() {
		return currentState.isAlive();
	}

	public void addNeighbour(Cell cell) {
		if (!neighbours.contains(cell)){
			neighbours.add(cell);
			cell.addNeighbour(this);
		}
		
	}

	public void calculateNextState() {
		nextState = currentState.nextStateFor(this);
	}

	public Collection<Cell> getNeighbours() {
		return neighbours;
	}

}
